		<?php 
			include($_SERVER['DOCUMENT_ROOT']."/headerins.php");
		?>

<?php

			include($_SERVER['DOCUMENT_ROOT']."/headerFrame.php");

echo'
        <div id="contextCaption">Список товаров.</div>
        <hr>
            <table border="0" id="contextGrid" cellspacing="0">
                <thead>
                    <tr>
                    	<th>№</th>
                    	<th>Код товара</th>
                        <th>Наименование</th>
                        <th>Группа</th>
                        <th>Ед. изм</th>
                        <th>Цена</th>
                        <th>Цена2</th>
                        <th>Балл</th>
                        <th>Актив</th>
                        <th>Изм</th>
                        <th>Уда</th>                        
                    </tr>
                </thead>
                <tbody>
     ';
?>
				<?php
                   
                          $sql = '
							SELECT
								m.id,
								m.code,
								m.name,
								mg.NAME AS groupname,
								md.NAME AS dimensionname,
								m.price1,
								m.price2,
								m.active,
								m.ball,
								groupid,
								m.dimensionid
							FROM material m
							left join matgroup mg on mg.id = m.groupid
							left join matdimension md on md.id = m.DimensionId

                          ';
                          $result = mysql_query($sql);
                            if (!$result) {
                                echo 'Ошибка запроса: ' . mysql_error();
                                exit;
                            }
                          while($row = mysql_fetch_array($result)){
                              echo "<tr>";
                              echo "<td> " .$row['id']. "</td>";
							  echo "<td> " . $row['code'] . "</td>";
                              echo "<td> " . $row['name'] . "</td>";               
							  echo "<td> " . $row['groupname'] . "</td>";
							  echo "<td> " . $row['dimensionname'] . "</td>";
							  echo "<td> " . str_replace(".",",",  $row['price1']) . "</td>";
							  echo "<td> " . str_replace(".",",",  $row['price2']) . "</td>";
							  echo "<td> " .str_replace(".",",",  $row['ball']) . "</td>";
							  echo "<td> " . $row['active'] . "</td>";

							  echo "<td>  <img onclick=".'"'."getPage('/core/Material/MaterialUpdate.php?id=".$row['id']."&code=".$row['code']."&name=".str_replace(" ", "%20", $row['name'])."&groupid=".$row['groupid']."&dimensionid=".$row['dimensionid']."&price1=".str_replace(".", ",", $row['price1'])."&price2=".str_replace(".", ",", $row['price2'])."&ball=".str_replace(".", ",", $row['ball'])."&active=".$row['active']."')".'"'." src='/../images/edit.png' alt='Изменить' widht=16 height=16> </td>";
                              
							  echo "<td>  <img onclick=".'"'."Request('Material','delete', '".$row['id']."')".'"'." src='/../images/delete.png' alt='Удалить' widht=16 height=16> </td>";
                              echo "</tr>";
                            }

                          mysql_close($con);
                ?>                
  
  <?php
  echo '
				</tbody>
            </table>
            <hr>
            <input id="button" type="Button"  value="Закрыть" title="закрыть" onclick="getPage('."'".'/core/context/context.html'."'".')">            
            <input id="button" type="Button" onclick="getPage('."'".'/core/Material/MaterialInsert.php'."'".')" value="Создать" title="Создать">
';
?>
